﻿using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ApiPlugin.Plugin
{
    public sealed class CustomActionDescriptorChangeProvider : IActionDescriptorChangeProvider
    {
        private CustomActionDescriptorChangeProvider() { }

        public static CustomActionDescriptorChangeProvider Instance { get; } = new CustomActionDescriptorChangeProvider();

        public CancellationTokenSource TokenSource { get; private set; }

        public IChangeToken GetChangeToken()
        {
            TokenSource = new CancellationTokenSource();
            return new CancellationChangeToken(TokenSource.Token);
        }

        /// <summary>
        /// 触发更新通知
        /// </summary>
        public void Notify()
        {
            TokenSource.Cancel();
        }
    }
}
